<?php
/**
 * create.php
 *
 *
 * @category    Madoqua
 * @package     Module
 * @subpackage  Blog
 */

/** base class */
require_once 'Madoqua/Form.php';

/** subforms */
require_once 'Zend/Form/SubForm.php';

/** html entities filter */
require_once 'Zend/Filter/HtmlEntities.php';

/**
 * Blog_Comment_Create
 *
 * form for comments
 *
 * @category    Madoqua
 * @package     Module
 * @subpackage  Blog
 */
class Blog_Comment_Create extends Madoqua_Form {

    /**
     * no html filter
     *
     * @var Zend_Filter_HtmlEntities
     */
    protected $_noHtml;

    /**
     * constructor
     */
    public function __construct() {
        parent::__construct();
        //bubble up

        $this->_noHtml = new Zend_Filter_HtmlEntities(array(
                'quotestyle' => ENT_COMPAT,
                'charset'    => 'UTF-8'
            )
        );
        //htmlentities filter for non-html fields

        $class = $this->getAttrib('class');
        $this->setAttrib('class', $class . ' comment-create');
        //set class attrib

        $nameForm = new Zend_Form_SubForm();
        //namesubform

        $nameForm->addElement('text', 'name', array(
            'label' => 'Name',
            'required' => true,
            'class' => 'name',
            'validators' => array(
                array('stringLength', 255, 3)
            ),
            'filters' => array(
               $this->_noHtml
            )
        ));
        //name

        $nameForm->addElement('text', 'email', array(
            'label' => 'Email',
            'required' => true,
            'class' => 'email',
            'validators' => array(
                'emailAddress',
                array('stringLength', 255, 3)
            ),
            'filters' => array(
               $this->_noHtml
            )
        ));
        //email

        $this->addSubForm($nameForm, 'standard');
        $this->standard->setLegend('Enter your name/email');
        //subform group for name and email

        $config = Madoqua_Application::getConfiguration();
        //configuration

        if ($config->comments->allow_openid) {
            //I can has openid?
            $openidForm = new Zend_Form_SubForm();
            //open id subform

            $openidForm->addElement('text', 'identifier', array(
                'label' => 'Open ID',
                'required' => true,
                'validators' => array()
            ));
            //openid

            $this->addSubform($openidForm, 'openid');
            $this->openid->setLegend('Use OpenID');
            //openid display group
        }

        $commentForm = new Zend_Form_SubForm();
        //the comment subform

        $commentForm->addElement('textarea', 'content', array(
            'label' => 'Comment',
            'required' => true,
            'validators' => array(),
            'filters' => array(
               $this->_noHtml
            )
        ));
        //content

        $this->addSubform($commentForm, 'comment');
        $this->comment->setLegend('Your comment');
        //the comment display group

        $this->addElement('submit', 'submit', array(
            'value' => 'Submit'
        ));
        //submit

    }
}